//
//  TSCellHomeViewController.m
//  TSListDemo
//
//  Created by qian on 2020/11/18.
//  Copyright © 2020 dvlproad. All rights reserved.
//

#import "TSCellHomeViewController.h"
#import <CQCellAndHeaderCollect/CQTitleTableViewSectionHeader.h>
#import <CQCellAndHeaderCollect/CQTitleResultTableViewCell.h>
#import <CQCellAndHeaderCollect/CQTitleSwitchTableViewCell.h>
#import <CQCellAndHeaderCollect/CQTitleInputTableViewCell.h>

@interface TSCellHomeViewController () <UITableViewDataSource, UITableViewDelegate> {
    
}

@end

@implementation TSCellHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupViews];
}

- (void)setupViews {
    UITableView *tableView = [[UITableView alloc] init];
    [tableView registerClass:[CQTitleResultTableViewCell class] forCellReuseIdentifier:@"CQTitleResultTableViewCell"];
    [tableView registerClass:[CQTitleSwitchTableViewCell class] forCellReuseIdentifier:@"CQTitleSwitchTableViewCell"];
    [tableView registerClass:[CQTitleInputTableViewCell class] forCellReuseIdentifier:@"CQTitleInputTableViewCell"];
    tableView.dataSource = self;
    tableView.delegate = self;
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
}


#pragma mark - UITableViewDataSource & UITableViewDelegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 44;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    CQTitleTableViewSectionHeader *headerView = [[CQTitleTableViewSectionHeader alloc] init];
    
    UIImage *image = [UIImage imageNamed:@"icon_info_qa"];
    NSString *title = NSLocalizedString(@"我的问答", nil);;
    NSString *prompt = [NSString stringWithFormat:@"(%zd/3)", section];;
    [headerView setupImage:image title:title prompt:prompt themeType:NO];
        
    return headerView;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger iRowCount = 6;
    return iRowCount;
}


- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 44;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//    BOOL isImageCell = indexPath.item % 2 == 0;
//    if (isImageCell) {
//        return 200;
//    } else {
//        return 60;
//    }
//}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.item == 0) {
        CQTitleSwitchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CQTitleSwitchTableViewCell" forIndexPath:indexPath];
        cell.title = @"通知权限";
        cell.swthOn = YES;
        return cell;
    } else if (indexPath.item == 1) {
        CQTitleResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CQTitleResultTableViewCell" forIndexPath:indexPath];
        cell.title = @"昵称";
        cell.result = @"我的名字";
        return cell;
    } else {
        CQTitleInputTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CQTitleInputTableViewCell" forIndexPath:indexPath];
        cell.title = @"性别";
        cell.result = @"";
        return cell;
    }
}

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.item == 0) {
        return NO;  // 禁止高亮
    }
    return YES;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSLog(@"点击了%zd-%zd", indexPath.section, indexPath.row);
    
    UITableViewCell *cell =  [tableView cellForRowAtIndexPath:indexPath];
    if ([cell isKindOfClass:[CQTitleResultTableViewCell class]]) {
        
    }
}



#pragma mark - Touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
